package com.action;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.bean.AdminBean;
import com.dao.AdminDao;
import com.exception.AdminException;
import com.exception.DBException;

public class AdminAction
{
	public void updateAdmin(HttpServletRequest request,
			HttpServletResponse response, AdminBean adminBean)
			throws DBException, AdminException
	{
		AdminDao adminDao = new AdminDao();
		adminDao.updateAdministrator(adminBean);

		try
		{
			response.getWriter().write(
					"<script>alert('modify successuly!')</script>");
			response.getWriter().write(
					"<script>self.location.href='/lab/welcome.jsp'</script>");
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
	}

	public void getAdmin(HttpServletRequest request,
			HttpServletResponse response, AdminBean adminBean)
			throws DBException, AdminException
	{
		AdminDao adminDao = new AdminDao();
		adminDao.getAdministratorAsID(adminBean);
		request.setAttribute("admin", adminBean);
		try
		{
			request.getRequestDispatcher("/lab_admin/adminInfo.jsp").forward(
					request, response);
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}

	}
}
